package com.bafa.email;


import java.util.Properties;

import javax.mail.*;
import javax.mail.internet.*;

public class Email {


	 public static void sendEmail(
			    String aFromEmailAddr, String[] aToEmailAddr,
			    String aSubject, String aBody
			  ){
		 		Properties props = new Properties();
				props.put("mail.smtp.host", "localhost");
			    Session session = Session.getDefaultInstance( props, null );
			    MimeMessage message = new MimeMessage( session );
			    try {
			      //the "from" address may be set in code, or set in the
			      //config file under "mail.from" ; here, the latter style is used
			      message.setFrom( new InternetAddress(aFromEmailAddr) );
				  InternetAddress[] to = new InternetAddress[aToEmailAddr.length];
				  
				  for(int i=0;i<aToEmailAddr.length;i++){
					  to[i] = new InternetAddress(aToEmailAddr[i]);
				  }
			      message.addRecipients(
			        Message.RecipientType.TO, to
			      );
			      message.setSubject( aSubject );
			      message.setText( aBody );
			      Transport.send( message );
			    }
			    catch (Exception ex){
			      System.err.println("Cannot send email. " + ex);
			    }
			  }



}
